import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/account/api/accountApi.dart';
import 'package:honeypotflutter/modules/account/page/account_signed_fail/view.dart';
import 'package:honeypotflutter/modules/account/page/account_signed_success/view.dart';
import 'package:honeypotflutter/public/public_get.dart';
import 'package:honeypotflutter/public/public_total.dart';
import 'package:honeypotflutter/publicBussine/loginInfo/bussine_userInfo.dart';

class AccountSignedLogic extends GetxController {
  UserInfoLogic userInfoLogic = Get.find<UserInfoLogic>();

  TextEditingController bankController = TextEditingController();
  TextEditingController phoneController = TextEditingController();

  /**
   * 提交
   * */
  submit() async {
    String bank = bankController.text;
    bool? isBank = GetUtils.isBlank(bank);
    if (isBank == null || isBank == false) {
      HLTotal.total("请输入银行卡");
      return;
    }

    String phone = phoneController.text;
    if (!GetUtils.isPhoneNumber(phone)) {
      HLTotal.total("请输入正确手机号码");
      return;
    }

    try {
      await AccountApi.signInfo(
        idCardNumber: userInfoLogic.userInfo.idCardNumber,
        accountName: userInfoLogic.userInfo.realName,
        bankCardNumber: bank,
        reservedPhoneNumber: phone,
      );
      HLGet.off(AccountSignedSuccessPage());
    } catch (error) {
      HLGet.to(AccountSignedFailPage());
    }
  }
}
